{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "68dbee24-cf81-471a-b331-3cf08d427e18",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "source": [
    "# Option to show/hide plot messages\n",
    "\n",
    "The option `plotMessage` allows to hide messages produced by sampling."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ea0aa561-34ee-4890-abd5-6bfa93863c30",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"jmiznB\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v4.0.1/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"jmiznB\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"jmiznB\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "46159eb1-3fb7-49de-b748-1fa76fde073e",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "val d = mapOf(\"x\" to MutableList(11) { it })"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "74defcf1-3a30-4762-abbd-14654a260973",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"xs3sEz\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"sampling\":{\n",
       "\"n\":10.0,\n",
       "\"name\":\"random\"\n",
       "},\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0]\n",
       "}\n",
       "}],\n",
       "\"computation_messages\":[\"sampling_random(n=10) was applied to [point/identity stat] layer\"]\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"xs3sEz\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "val p = letsPlot(d) + geomPoint(sampling = samplingRandom(n = 10)) { x = \"x\" }\n",
    "p"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83304039-01a4-40f9-862b-c428bc97f7e0",
   "metadata": {},
   "source": [
    "### Using the `plotMessage` parameter\n",
    "Use `elementBlank()` to show no messages, or `elementText()` to show sampling messages. Note that `elementText()` options don't affect a message text."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "61d91358-85cc-44cb-a1cc-c52ca61c43db",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"L7n8gY\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"sampling\":{\n",
       "\"n\":10.0,\n",
       "\"name\":\"random\"\n",
       "},\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"plot_message\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"L7n8gY\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p + theme(plotMessage=elementBlank())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26e5886e-e3e5-4fcc-bfab-3cea5ac3ffa0",
   "metadata": {},
   "source": [
    "### Hiding plot messages for the whole notebook\n",
    "\n",
    "Using the `LestPlot.theme` property messages can be suppressed for the whole notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f6f2ee74-8d2e-4fa0-b5dc-44b0bd16c74f",
   "metadata": {},
   "outputs": [],
   "source": [
    "LetsPlot.theme = theme(plotMessage = elementBlank())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f038cfd6-216d-41e1-a415-c1f7c3219107",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"CjAZrY\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "},\n",
       "\"data\":{\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"x\":\"x\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"sampling\":{\n",
       "\"n\":10.0,\n",
       "\"name\":\"random\"\n",
       "},\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"data\":{\n",
       "\"x\":[0.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0]\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"plot_message\":{\n",
       "\"blank\":true\n",
       "}\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"CjAZrY\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "letsPlot(d) + geomPoint(sampling = samplingRandom(n = 10)) { x = \"x\" }"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
